//promise  容器  

let arr = [];

function add(i){
    return new Promise((resolve,reject) => {
        setTimeout(() => {
            arr.push(i);
            console.log(arr); //[]
            reject('errro')
        },1000)
    })
}
async function addAsync(){
    for(let i =0;i<10;i++){
        await add(i)
    }
}
addAsync();

//

let result = {
    allPrice:'所有商品的总价格',
    group:[
        {
            typeName:'水果',
            price:'所有水果的总价格'
        },
        {
            typeName:'蔬菜',
            price:'所有蔬菜的总价格'
        }
    ]
} 



const car = [
    {
        groupName:'水果',
        type:[
            {
                name:'苹果',
                price:10
            },
            {
                name:'橘子',
                price:40
            },
            {
                name:'香蕉',
                price:90
            }
        ]
    },
    {
        groupName:'蔬菜',
        type:[
            {
                name:'芹菜',
                price:10
            },
            {
                name:'菠菜',
                price:15
            },
            {
                name:'土豆',
                price:8
            }
        ]
    }
];

function computedPrice(data){
    let results = {
        allPrice:0,
        group:[]
    };

    data.forEach(item => {
        results.group.push({typeName:item.groupName,price:item.type.reduce((pre,cur) => {
            results.allPrice += cur.price;
            return pre + cur.price
        },0)})
    })

    return results
}

console.log(computedPrice(car));




